//
//  CQAddActionTableViewCell.m
//  TSListDemo
//
//  Created by qian on 2020/11/19.
//  Copyright © 2020 dvlproad. All rights reserved.
//

#import "CQAddActionTableViewCell.h"
#import <Masonry/Masonry.h>
#import <CJBaseUIKit/UIColor+CJHex.h>
#import <CJContainer/CQHorizontalImageLabelView.h>
#import "UIImage+CQCellBundle.h"

@interface CQAddActionTableViewCell () {
    
}
@property (nonatomic, strong) UIView *promptAndTitleContainer;

@property (nonatomic, strong) CQHorizontalImageLabelView *imageLabelView;
@property (nonatomic, strong) UILabel *promptLabel;


@end

@implementation CQAddActionTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    return self;
}

#pragma mark - Setter
- (void)updateTitle:(NSString *)title prompt:(NSString *)prompt {
    _title = title;
    self.imageLabelView.titleLable.text = title;
    
    self.promptLabel.text = prompt;
    if (prompt.length > 0) {
        [self.promptAndTitleContainer mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).mas_offset(46);
        }];
        [self.promptLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(22);
        }];
        [self.imageLabelView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.promptLabel.mas_bottom).mas_offset(20);
        }];
    } else {
        [self.promptAndTitleContainer mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).mas_offset(20);
        }];
        [self.promptLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
        [self.imageLabelView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.promptLabel.mas_bottom).mas_offset(0);
        }];
    }
}

#pragma mark - Event
- (void)updateThemeType:(BOOL)isBlack {
    if (isBlack) {
        self.backgroundColor = CJColorFromHexString(@"#26262C");
        self.imageLabelView.titleLable.textColor = CJColorFromHexString(@"#FFFFFF");
        self.imageLabelView.imageView.image = [UIImage cell_addImage_default];
    } else {
        self.backgroundColor = CJColorFromHexString(@"#FFFFFF");
        self.imageLabelView.titleLable.textColor = CJColorFromHexString(@"#0C101B");
        self.imageLabelView.imageView.image = [UIImage cell_addImage_default];
    }
}

#pragma mark - SetupViews
- (void)setupViews {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    // prompt 和 title 的容器
    UIView *promptAndTitleContainer = [[UIView alloc] init];
    [self addSubview:promptAndTitleContainer];
    [promptAndTitleContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self);
        make.centerX.equalTo(self);
        make.top.equalTo(self).mas_offset(20);
        make.centerY.equalTo(self);
    }];
    self.promptAndTitleContainer = promptAndTitleContainer;
    
    UILabel *promptLabel = [[UILabel alloc] init];
    promptLabel.backgroundColor = [UIColor clearColor];
    promptLabel.textAlignment = NSTextAlignmentCenter;
    promptLabel.textColor = CJColorFromHexString(@"#B6B7BA");
    promptLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
    [promptAndTitleContainer addSubview:promptLabel];
    [promptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(promptAndTitleContainer);
        make.centerX.equalTo(promptAndTitleContainer);
        make.top.equalTo(promptAndTitleContainer);
        make.height.mas_equalTo(22);
    }];
    self.promptLabel = promptLabel;
    
    CQHorizontalImageLabelView *imageLabelView = [[CQHorizontalImageLabelView alloc] initWithIconHeight:16
                                                                   iconTitleSpacing:8
                                                         contentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    [promptAndTitleContainer addSubview:imageLabelView];
    [imageLabelView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(promptAndTitleContainer);
        make.top.equalTo(promptLabel.mas_bottom).mas_offset(20);
        make.bottom.equalTo(promptAndTitleContainer);
        make.height.mas_equalTo(@20);
    }];
    self.imageLabelView = imageLabelView;
    
    imageLabelView.titleLable.textColor = CJColorFromHexString(@"#0C101B");
    imageLabelView.titleLable.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:14];
    imageLabelView.imageView.image = [UIImage cell_addImage_default];

    
    
    self.accessoryType = UITableViewCellAccessoryNone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
